
import locale 

def format_currency(x):
	"""
	>>> format_currency(123)
	'123'

	>>> format_currency(1234)
	'1,234'

	>>> format_currency(1234567890)
	'1,234,567,890'
	"""
	if type(x) not in [type(0), type(0L)]:
		raise TypeError("Parameter must be an integer.")
	if x < 0:
		return '-' + intWithCommas(-x)
	result = ''
	while x >= 1000:
		x, r = divmod(x, 1000)
		result = ",%03d%s" % (r, result)
	return "%d%s" % (x, result)


if __name__ == "__main__":
    import doctest
    doctest.testmod()

